package cn.tedu.spring.example;

import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;

/**
 * 测试User
 */
public class TestUser {
    public static void main(String[] args) throws ClassNotFoundException, InstantiationException, IllegalAccessException {
        /*
            方式1: new
         */
        User user1 = new User();
        user1.run();

        /*
            方式2: 反射机制
         */
        Class<?> cls = Class.forName("cn.tedu.spring.example.User");
        User user2 = (User) cls.newInstance();
        user2.run();

        /*
            方式3: spring框架创建
         */
        //由spring框架创建的对象, 叫Spring Bean对象, 简称Bean对象
        //Bean对象与普通java对象无区别, 只是区分创建者的身份(框架/开发者)
        //复制包名的快捷键: ctrl+shift+alt+c
        //自动补全类的引用/返回值: new Object().var + enter / method().var + enter
        ApplicationContext context = new AnnotationConfigApplicationContext
                ("cn.tedu.spring.example");
        User user3 = context.getBean(User.class);
        user3.run();
    }
}
